package test.tradeflow;

import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2023/1/8 18:04
 * @ Description:
 */
@Component
public class TradeFlowRuner {
    @Autowired
    private ApplicationContext applicationContext;
    private TradeFlowRuner() {
    }

    public  <T, R> R execute(String flowName, TradeContext<T, R> context) {
        //交易执行
        TradeFlow tradeFlow = (TradeFlow) applicationContext.getBean(flowName);
        tradeFlow.execute(context);

        return context.getRspMsg();
    }

    public static <T, R> R execute(TradeFlow tradeFlow, TradeContext<T, R> context){
        tradeFlow.execute(context);
        return context.getRspMsg();
    }
}
